<?php
// RSS页面
include("common.inc.php");
include(INC_PATH."/group.class.php"); //包含团购类
$gp=new GroupClass();
//判断后台是否设置首页显示团购ID
if(GetNum($cfg_index_group)){
	$gid=GetNum($cfg_index_group);
}else {
	//自动显示当天ID团购
	$todaystart=strtotime(date('Y-m-d 0:0:0',time()));
	$todayend=strtotime(date('Y-m-d 0:0:0',time()+3600*24));
	$now=time();
	$wheresql="group_end_time >= $now and state = 1 {$citywhere}";
	//$wheresql="TO_DAYS(group_begin_time) = TO_DAYS(NOW())";
	$returnarray = $gp->getdata(1,"",$wheresql);
	//print_r($returnarray);
	$gid=$returnarray[0]['gid'];//设置查询到的gid
	unset($returnarray);	//清空数组
	
}
if(empty($gid))dheader("mail.php");//php跳转页面

$value=$gp->getone($gid); 	//获取团购信息
//print_r($value);

$rssarr = array(
	'charset' => "utf-8",
	'title' => $cfg_site_name,
	'link' => $cfg_site_url,
	'description' => $cfg_site_description,
	'copyright' => 'Copyright(C) '.$cfg_site_name,
	'generator' => 'zzqss',
	'lastBuildDate' => date("Y-m-d"),
	'items' => array()
);
$rssarr['items'][1]=array(
"title"=>$value['title'],
"link"=>$cfg_site_url."/view.php?gid=".$value['gid'],
"description"=>$value['goods_about'],
"category"=>$value['title'],
"author"=>$value['title'],
"pubDate"=>date('Y-m-d',$value['group_begin_time'])

);

showrss($rssarr);

function showrss($rssarr) {
	header("Content-type: application/xml");
	echo '<?xml version="1.0" encoding="'.$rssarr['charset'].'"?>
			<rss version="2.0">
			  <channel>
			    <title>'.$rssarr['title'].'</title>
			    <link>'.$rssarr['link'].'</link>
			    <description>'.$rssarr['description'].'</description>
			    <copyright>'.$rssarr['copyright'].'</copyright>
			    <generator>'.$rssarr['generator'].'</generator>
			    <lastBuildDate>'.$rssarr['lastBuildDate'].'</lastBuildDate>';
			    if(!empty($rssarr['items'])) {
				    foreach($rssarr['items'] as $key => $value) {
				    	echo '<item>
								<title>'.$value['title'].'</title>
								<link>'.$value['link'].'</link>
								<description><![CDATA['.$value['description'].']]></description>
								<category>'.$value['category'].'</category>
								<author>'.$value['author'].'</author>
								<pubDate>'.$value['pubDate'].'</pubDate>
							</item>
							';
				    }
			    }
	echo '
		</channel>
	</rss>';
}


?>